﻿using System;
using Dexter.Core.EventArgs;
using Dexter.Domain.Model;
using Dexter.Domain.Results;
using Dexter.Logger.Contracts;
using Dexter.Repository;

namespace Dexter.Services.Implementation {
	/// <summary>
	/// 	The implementatio of <see cref="ILegacyUrlService" /> .
	/// </summary>
	public class LegacyUrlService : ILegacyUrlService {
		/// <summary>
		/// 	An instance of a concrete implementation of <see cref="ILegacyUrlRepository" />
		/// </summary>
		protected readonly ILegacyUrlRepository LegacyUrlRepository;

		/// <summary>
		/// 	The logger
		/// </summary>
		protected readonly ILogger Logger;


		public LegacyUrlService(ILegacyUrlRepository legacyUrlRepository, ILogger logger) {
			LegacyUrlRepository = legacyUrlRepository;
			Logger = logger;
		}

		#region ILegacyUrlService Members

		public IPagedResult<LegacyUrl> GetListPaged(int pageIndex, int pageSize) {
			IPagedResult<LegacyUrl> data = this.GetListPaged(pageIndex, pageSize, true);

			LegacyUrlRetrieved.Raise(this, new GenericEventArgs<IPagedResult<LegacyUrl>>(data));

			return data;
		}

		public IPagedResult<LegacyUrl> GetListPaged(int pageIndex, int pageSize, bool enableTracking) {
			IPagedResult<LegacyUrl> data = LegacyUrlRepository.GetListPaged(pageIndex, pageSize, enableTracking);

			LegacyUrlRetrieved.Raise(this, new GenericEventArgs<IPagedResult<LegacyUrl>>(data));

			return data;
		}

		public event EventHandler<GenericEventArgs<IPagedResult<LegacyUrl>>> LegacyUrlRetrieved;

		#endregion
	}
}